<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

//门店模型
//苑立彬
class SystemStore extends Model
{
    use HasFactory;

    public $timestamps = false;
    protected $table = 'system_store';
    protected $guarded = [];


    //门店列表
    public static function shoplist($num, $where)
    {
        return self::where($where)->where('is_del', 0)->paginate($num);
    }

    /**
     * 添加
     * @param $data
     * @return mixed
     */
    public static function create_store($data)
    {
        $data['day_time'] = $data['day_time'] . "-" . $data['day_time2'];
        unset($data['day_time2']);
        return self::create($data);
    }

    /**
     * 删除
     * @param $id
     * @return mixed
     */
    public static function delModel($id)
    {
        return self::where('id', $id)->update(['is_del' => 1]);
    }

    /**
     * 修改详情
     * @param $id
     * @return mixed
     */
    public static function editModel($id)
    {
        return self::find($id);
    }

    /**
     * 数据修改
     * @param $id
     * @param $data
     * @return mixed
     */
    public static function storeUpdate($id, $data)
    {
        $data['day_time'] = $data['day_time'] . "-" . $data['day_time2'];
        unset($data['day_time2']);
        return self::where("id", $id)->update($data);
    }

    /**
     * 审核
     * @param $id
     * @param $data
     * @return mixed
     */
    public static function update_status($id, $data)
    {
        return self::where('id', $id)->update([
            'status'=>$data['status'],
            'status_desc'=>$data['status_desc']
        ]);
    }

    /**
     * 获取门店列表
     * @return mixed
     */
    public static function list()
    {
        return self::where('is_show', 1)->where('status', 1)->paginate(5);
    }

    /**
     * 获取门店详情信息
     * @param $id
     * @return mixed
     */
    public static function read($id)
    {
        return self::where('id', $id)->first();
    }
}
